package com.glsc.ngateway.common.api.flowable.dto.demand;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lixing
 * <p>
 * {
 * "document":
 * {
 * "fileType": "xlsx",
 * "key": "secret",
 * "title": "Example Spreadsheet Title.xlsx",
 * "url": "http://10.1.81.196/glam/%E9%AB%98%E7%AE%A1%E9%A9%BE%E9%A9%B6%E8%88%B1_20191018_20200824160018395.xlsx"
 * },
 * "documentType": "spreadsheet"
 * "editorConfig":
 * {
 * "mode": "view"
 * },
 * "height": "100%",
 * "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb2N1bWVudCI6eyJmaWxlVHlwZSI6Inhsc3giLCJrZXkiOiJzZWNyZXQiLCJ0aXRsZSI6IkV4YW1wbGUgU3ByZWFkc2hlZXQgVGl0bGUueGxzeCIsInVybCI6Imh0dHA6Ly8xMC4xLjgxLjE5Ni9nbGFtLyVFOSVBQiU5OCVFNyVBRSVBMSVFOSVBOSVCRSVFOSVBOSVCNiVFOCU4OCVCMV8yMDE5MTAxOF8yMDIwMDgyNDE2MDAxODM5NS54bHN4In0sImRvY3VtZW50VHlwZSI6InNwcmVhZHNoZWV0IiwiZWRpdG9yQ29uZmlnIjp7Im1vZGUiOiJ2aWV3In0sImhlaWdodCI6IjEwMCUiLCJ3aWR0aCI6IjEwMCUifQ.LnHWaygRxzUTgdR9JVcGz1bVMGTdhVSuIY4UtTB5iCA",
 * "width": "100%"
 * }
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ReportShowResponse {
    private Document document;
    //private String type = "embedded";
    private String documentType;
    private Map<String, Object> editorConfig = new HashMap<String, Object>();
    private String token;
    private String height = "95%";
    private String width = "100%";

    public ReportShowResponse(String title, String url, FileType filetype) {
        this.documentType = filetype.getOnlyofficeDocumentType();
        this.document = new Document(title, url, filetype);
    }

    public ReportShowResponse(String title, String url, String token, FileType filetype) {
        this.documentType = filetype.getOnlyofficeDocumentType();
        this.document = new Document(title, url, filetype);
        editorConfig.put("lang", "zh-CN");
        editorConfig.put("mode", "view");
        editorConfig.put("customization", new HashMap<String, Boolean>() {{
            put("chat", false);
            put("comments", false);
            put("compactHeader", true);
            put("compactToolbar", true);
            put("plugins", false);
        }});

        this.token = token;
    }

}

@Data
@AllArgsConstructor
@NoArgsConstructor
class Document {

    String fileType;
    String key = "" + System.currentTimeMillis();
    String title;
    String url;
    Map<String, Boolean> permissions;

    public Document(String title, String url, FileType filetype) {
        super();
        this.title = title;
        this.url = url;
        this.fileType = filetype.toString();
        permissions = new HashMap<String, Boolean>();
        permissions.put("download", false);
        permissions.put("print", false);

    }

}
